package ${package}.${moduleName}.service.impl;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${package}.${moduleName}.core.LoginUtil;
import ${package}.${moduleName}.dao.${ClassName}Dao;
import ${package}.${moduleName}.dto.request.${ClassName}PageRequest;
import ${package}.${moduleName}.dto.request.${ClassName}Request;
import ${package}.${moduleName}.dto.response.${ClassName}Response;
import ${package}.${moduleName}.entity.${ClassName};
import ${package}.${moduleName}.service.${ClassName}Service;
import ${package}.${moduleName}.service.CustomerPrepaidService;
import ${package}.${moduleName}.service.CustomerService;
import ${package}.${moduleName}.service.purchase.ProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;


/**
 * ${tableComment}
 *
 * @author ${author} ${email}
 * @since ${version} ${date}
 */
@Service
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Dao, ${ClassName}> implements ${ClassName}Service {


    /**
    * 分页查询${tableComment}信息
    *
    * @param page 分页信息
    * @return IPage<${ClassName}Response> ${tableComment}列表分页
    */
    @Override
    public IPage<${ClassName}Response> page${ClassName}(${ClassName}PageRequest page) {
        IPage<${ClassName}Response> ipage = new Page<>();
        IPage<${ClassName}> currenPage = this.page(page.toMybatisPage(),  Wrappers.lambdaQuery());
        ipage.setPages(currenPage.getPages());
        ipage.setSize(currenPage.getSize());
        ipage.setTotal(currenPage.getTotal());
        ipage.setCurrent(currenPage.getCurrent());
        if (CollUtil.isNotEmpty(currenPage.getRecords())) {
        ipage.setRecords(currenPage.getRecords().stream().map(items -> get${ClassName}Detailget(items.getId())).collect(Collectors.toList()));
        }

        return ipage;
    }

    /**
    * 根据id获取${tableComment}
    *
    * @param id ${tableComment}id
    * @return ${ClassName}Response ${tableComment}
    */
    @Override
    public ${ClassName}Response get${ClassName}Detail(Long id) {
            ${ClassName} ${ClassName?uncap_first} = this.getById(id);
        if (ObjectUtil.isNotEmpty(${ClassName?uncap_first})) {
            ${ClassName}Response ${ClassName?uncap_first}Response = new ${ClassName}Response();
            BeanUtil.copyProperties(${ClassName?uncap_first}, ${ClassName?uncap_first}Response);
            return ${ClassName?uncap_first}Response;
        }
     return null;
    }

    /**
    * 新增${tableComment}
    *
    * @param ${ClassName?uncap_first}Request ${tableComment}
    * @return
    */
    @Override
    public Boolean save${ClassName}(${ClassName}Request ${ClassName?uncap_first}Request) {
        ${ClassName} ${ClassName?uncap_first} = new ${ClassName}();
        BeanUtil.copyProperties(${ClassName?uncap_first}Request, ${ClassName?uncap_first});
        ${ClassName?uncap_first}.setId(null);
        ${ClassName?uncap_first}.setCreatedNameBy(LoginUtil.getUserName());
        return this.save(${ClassName?uncap_first});
    }

    /**
    * 修改${tableComment}
    *
    * @param {ClassName?uncap_first}Request ${tableComment}
    * @return
    */
    @Override
    public Boolean update${ClassName}(${ClassName}Request ${ClassName?uncap_first}Request) {
        ${ClassName} ${ClassName?uncap_first} = new ${ClassName}();
        BeanUtil.copyProperties(${ClassName?uncap_first}Request, ${ClassName?uncap_first});
        return this.updateById(${ClassName?uncap_first});
    }

    /**
    * 批量${tableComment}
    *
    * @param idlist id集合
    * @return false-失败 true-成功
    */
    @Override
    public Boolean batchdel${ClassName}(List<Long> idlist) {
        return this.removeByIds(idlist);
    }

}